<?php
defined('JOC') or die;

class Form extends Module 
{
	private $arrFields = Array() ;
  
	function __construct($module_id = 0)
	{
		$module_field = new Module_field_model($module_id) ;

		$this->arrFields = $module_field->getFields() ;
    
 //   debug::pr($this->arrFields,'',true) ;
		
		$this->processFields() ;
	}
	function processFields($level = 0)
	{
		if($this->arrFields)
		{
			$this->_elements = Array() ;
			
			foreach($this->arrFields as $field)
			{
				$tmp_element = $field ;
				
				$tmp_element['class'] 						= '' ;
				
				if($field['foreign'] == 1)
				{
          /* $field['foreign_type'] == 1 => Combo */
          if($field['foreign_type'] == 1)
          {
            $tmp_element['tag_beg_1'] 			= '<select' ;
            $tmp_element['content_beg']     = '>' ;
            $tmp_element['content'] 				= '<option value="1" >1 : Default</option>' ;
            $tmp_element['tag_end'] 				= '</select>' ;
          }
          /* $field['foreign_type'] == 2 => Drag and Drop */
          if($field['foreign_type'] == 2)
          {
            $tmp_element['tag_beg_1'] 			= '<div' ;
            $tmp_element['tag_beg_2'] 			= '' ;
            $tmp_element['data-sortable'] 	= 'data-sortable="true"' ;
            $tmp_element['drop_container'] 	= 'data-dropcontainer="true" dropzone="true" data-dropaccept="4" ' ;
            $tmp_element['content_beg']     = '>DRAG_AND_DROP<ul>' ;
            $tmp_element['content'] 				= '' ;
            $tmp_element['content_end']     = '</ul>' ;
            $tmp_element['tag_end'] 				= '</div>' ;
          }
				}
				else if($field['richtext'] == 1)
				{
					$tmp_element['tag_beg_1'] 			= '<div' ;
					$tmp_element['tag_beg_2'] 			= '' ;
					$tmp_element['contenteditable'] = 'contenteditable="true"' ;
          $tmp_element['content_beg']     = '>' ;
					$tmp_element['content'] 				= '&nbsp;' ;
					$tmp_element['tag_end'] 				= '</div>' ;
				}
				else
				{
					$tmp_element['tag_beg_1'] 			= '<input' ;
					$tmp_element['tag_beg_2'] 			= '' ;
          $tmp_element['placeholder'] 		= 'placeholder="'.$tmp_element['field_name'].'"' ;
          $tmp_element['content_beg']     = 'value="' ;
          $tmp_element['content'] 				= '' ;
          $tmp_element['content_end']     = '"' ;
					$tmp_element['tag_end'] 				= '/>' ;
				}
				$tmp_element['id'] 						= '' ;
				$tmp_element['class'] 				.= '' ;
				
				$this->_elements[] = $tmp_element ;
			}
//      debug::pr($this->_elements,'',true) ;
		}
	}
	function getJavascript()
	{
		return '' ;
	}
	function Validate(){
		
	}
}